package com.city.cmsservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.city.cmsservice.entity.CrmBanner;
import com.city.cmsservice.mapper.CrmBannerMapper;
import com.city.cmsservice.service.CrmBannerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 首页banner表 服务实现类
 * </p>
 *
 * @author city
 * @since 2020-09-20
 */
@Service
public class CrmBannerServiceImpl extends ServiceImpl<CrmBannerMapper, CrmBanner> implements CrmBannerService {

    @Cacheable(key = "'selectIndexList'",value = "banner")
    //开启redis查询缓存，第一次查询后放入redis  nosql数据库中，第二次直接访问redis，但是有个时效
    @Override
    public List<CrmBanner> seleteAllBanner() {
        QueryWrapper<CrmBanner> queryWrapper=new QueryWrapper<>();
        queryWrapper.orderByDesc("id");
        //通过limit筛选出根据id排序的前两条数据，但是mybatisplus没有这么方法，但是提供了last
        //可以通过last来在sql语句后边拼接语句
        queryWrapper.last("limit 8");
        List<CrmBanner> crmBanners = baseMapper.selectList(queryWrapper);
        return crmBanners;
    }
}
